<?php
    /* 
    *接口说明:  获取自己提交的订餐统计记录
    *创建者: 	kai
    *时间:	  	20180319
    */
    //echo "<meta http-equiv='Content-Type'' content='text/html; charset=utf-8'>";
    // 设置时区
    date_default_timezone_set('Etc/GMT-8');
    require_once 'commom/dbfunction.php';
    require_once 'commom/config.php';
    $arrResult = null;
    $conn = null;
    do{
        // 参数检查
        $json_infoString = isset($_GET['info']) ? $_GET['info'] : '';
        if(empty($json_infoString)){
            $arrResult = array(
                        "errcode" => 1,
                        "info" => "get参数为空",
                        );
            break;
        }

        // 从传入参数中获取需要的信息
        $json_info = json_decode($json_infoString, true);
        // 获取信息
        $publisheropenid = "";
        if(isset($json_info['publisheropenid'])){
			$publisheropenid = $json_info['publisheropenid'];
        }

        // 参数检查
        if(empty($publisheropenid)){
            $arrResult = array(
                "errcode" => 2,
                "info" => "上传信息不足. publisheropenid=".$publisheropenid,
                );
            break;
        }

        // 获取数据库链接
        // 创建连接
        $conn = mysqli_connect(DB_HOST, DB_USER, DB_PWD);
        // 检测连接
        if (!$conn) {
            $arrResult = array(
                "errcode" => 3,
                "info" => "连接mysql数据库失败：". mysqli_connect_errno().":".mysqli_connect_error(),
            );
            break;
        }
        mysqli_set_charset($conn, "utf8");
        // 选择数据库
        if(!mysqli_select_db($conn, DB_DBNAME)){
            $arrResult = array(
                "errcode" => 4,
                "info" => "选择mysql数据库失败：". mysqli_connect_errno().":".mysqli_connect_error(),
            );
            break;
        }

        // 根据shareuniqueid和publisheropenid获取分享的记录
        // 只取最新的100条
        $QueryOrderStatSql = "select * from orderstat where publisheropenid='" . $publisheropenid."'  ORDER BY no LIMIT 100";
        $result = mysqli_query($conn, $QueryOrderStatSql);
        if(!$result){
            $arrResult = array(
                "errcode" => 5,
                "info" => "查询orderstat数据库失败。publisheropenid=". $publisheropenid,
            );
            break;
        }

        // 输出所有满足条件的记录
        $arrayRecord = array();
        $index = 0;
        while($row = mysqli_fetch_assoc($result))
        {
            $arrayRecord[] = $row;
        }

        // 输出结果
		$arrResult = array(
					"errcode" => 0,
					"info" => json_encode($arrayRecord),
					);
    }while(false);

    // 数据库链接清理
    if($conn){
        mysqli_close($conn);
    }

    // 输出结果
    echo json_encode($arrResult);
?>